#include "simple_input.h"
#include "tetris_game.h"
#include "SDL.h"

void Input_Process() {
	SDL_Event event;
	while ( SDL_PollEvent(&event) ) {
		if ( event.type == SDL_QUIT ) {
			exitFlag = 1;
		}
		if ( event.type == SDL_KEYDOWN ) {
		
			switch(event.key.keysym.sym) {
				
				case SDLK_ESCAPE:
					if(gameState == STATE_MENU){
						exitFlag = 1;
					} else {
						Game_FadeAndChangeState(STATE_MENU);
					}
				break;
				case SDLK_LEFT:
					if(gameState == STATE_GAME){
						Game_MoveBlock(MOVE_LEFT);
					} else if(gameState == STATE_OPTIONS) {
						Game_MenuMove(MENU_LEFT);
					}
				break;
				case SDLK_RIGHT:
					if(gameState == STATE_GAME){
						Game_MoveBlock(MOVE_RIGHT);
					} else if(gameState == STATE_OPTIONS) {
						Game_MenuMove(MENU_RIGHT);
					}
				break;
				case SDLK_DOWN:
					if(gameState == STATE_MENU || gameState == STATE_OPTIONS){
						Game_MenuMove(MENU_DOWN);
					} else {
						Game_MoveBlock(MOVE_DOWN);
					}
				break;
				case SDLK_SPACE:
					Game_DropBlock();
				break;
				case SDLK_UP:
					if(gameState == STATE_MENU || gameState == STATE_OPTIONS){
						Game_MenuMove(MENU_UP);
					} else {
						Game_RotateBlock();
					}
				break;
				case SDLK_RETURN:
					if(gameState == STATE_MENU || gameState == STATE_OPTIONS) {
						Game_MenuOK();
					}
				break;
				default:
				break;
			}	
		}
	}
}
